home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / PowerTools.lha / PowerTools / PowerTools.s < prev    next >
Encoding:
Text File  |  2002-02-06  |  6.8 KB  |  312 lines

  1.     include     devices/timer.i
  2.     include     dos/datetime.i
  3.     include     dos/dos.i
  4.     include     exec/io.i
  5.     include     exec/exec_lib.i
  6.     include     graphics/graphics_lib.i
  7.     include     libraries/dos_lib.i
  8.  
  9.     lea     dosname(pc),a1                ;Init devices and libs
  10.     move.l     #36,d0
  11.     CALLEXEC OpenLibrary
  12.     move.l     #ERROR_INVALID_RESIDENT_LIBRARY,d3
  13.     move.l     d0,dosbase
  14.     beq     doserr
  15.     move.b     #-1,d0
  16.     jsr     _LVOAllocSignal(a6)
  17.     move.b     d0,signum
  18.     move.l     #ERROR_NO_FREE_STORE,d3
  19.     beq     sigerr
  20.     jsr     _LVOCreateMsgPort(a6)
  21.     move.l     #ERROR_NO_FREE_STORE,d3
  22.     move.l     d0,msgport
  23.     beq     mperror
  24.     move.l     d0,a0
  25.     move.l     #IOTV_SIZE,d0
  26.     jsr     _LVOCreateIORequest(a6)
  27.     move.l     d0,ioreq
  28.     beq     reqerr
  29.     move.l     d0,a1
  30.     lea     devname(pc),a0
  31.     moveq.l     #UNIT_VBLANK,d0
  32.     clr.l     d1
  33.     jsr     _LVOOpenDevice(a6)
  34.     tst.l     d0
  35.     bne     deverr
  36.     move.l     #argstr,d1                ;Parse arguments
  37.     move.l     #tmpname,d2
  38.     clr.l     d3
  39.     move.l     dosbase(pc),a6
  40.     jsr     _LVOReadArgs(a6)
  41.     move.l     d0,rdargs
  42.     jsr     _LVOIoErr(a6)
  43.     move.l     d0,d3
  44.     tst.l     rdargs
  45.     beq     argserr
  46.     move.l     #0,a1
  47.     CALLEXEC FindTask
  48.     move.l     d0,sigtask
  49.     move.l     logname(pc),d1                ;Open (or create) logfile
  50.     move.l     #MODE_READWRITE,d2
  51.     move.l     dosbase(pc),a6
  52.     jsr     _LVOOpen(a6)
  53.     move.l     d0,logfile
  54.     jsr     _LVOIoErr(a6)                ;Save error code for case of fault
  55.     move.l     d0,d3
  56.     move.l     logfile(pc),d1
  57.     tst.l     d1
  58.     beq     logerr
  59.     move.l     #volume1,d2                ;Get logfile device name
  60.     move.l     #33,d3
  61.     jsr     _LVONameFromFH(a6)
  62.     lea     volume1(pc),a0
  63.     bsr     finddn
  64.     move.l     logfile(pc),d1                ;Set current offset to the end of logfile
  65.     clr.l     d2
  66.     move.l     #OFFSET_END,d3
  67.     jsr     _LVOSeek(a6)
  68.     move.l     tmpname(pc),d1                ;Open (or create) timefile
  69.     move.l     #MODE_READWRITE,d2
  70.     move.l     dosbase(pc),a6
  71.     jsr     _LVOOpen(a6)
  72.     move.l     d0,tmpfile
  73.     jsr     _LVOIoErr(a6)                ;Get error code
  74.     move.l     d0,d3
  75.     move.l     tmpfile(pc),d1
  76.     tst.l     d1                    ;Fail it there was an error
  77.     beq     tmperr2
  78.     move.l     #volume2,d2                ;Get timefile device name
  79.     move.l     #33,d3
  80.     jsr     _LVONameFromFH(a6)
  81.     lea     volume2(pc),a0
  82.     bsr     finddn
  83.     move.l     tmpfile(pc),d1                ;Try to read datestamp from timefile
  84.     move.l     #days,d2
  85.     move.l     #12,d3
  86.     jsr     _LVORead(a6)
  87.     tst.l     d0                    ;If failed, this file is just created,
  88.     beq     normal                    ;and there was no failure
  89.     bsr     putdate                ;Otherwise store failure time
  90.     move.l     logfile(pc),d1                ;Store warning text
  91.     move.l     #warntxt,d2
  92.     jsr     _LVOFPuts(a6)
  93. normal    move.l     #days,d1                ;Take current date
  94.     jsr     _LVODateStamp(a6)
  95.     bsr     putdate                ;Put current date into file
  96.     move.l     logfile(pc),d1                ;Print 'started' string to file
  97.     move.l     #starttx,d2
  98.     jsr     _LVOFPuts(a6)
  99.     move.l     tmpfile(pc),d1                ;Close timefile
  100.     jsr     _LVOClose(a6)
  101.     move.l     logfile(pc),d1
  102.     jsr     _LVOClose(a6)
  103.     move.l     4.w,a1
  104.     move.w     #_LVOColdReboot,a0
  105.     move.l     #newcrb,d0
  106.     move.l     a1,a6
  107.     jsr     _LVOSetFunction(a6)
  108.     move.l     d0,oldcrb
  109. loop    move.l     #days,d1
  110.     move.l     dosbase(pc),a6
  111.     jsr     _LVODateStamp(a6)
  112.     move.l     tmpname(pc),d1
  113.     move.l     #MODE_NEWFILE,d2
  114.     jsr     _LVOOpen(a6)
  115.     move.l     d0,tmpfile
  116.     beq     tmperr
  117.     move.l     d0,d1
  118.     move.l     #days,d2
  119.     move.l     #12,d3
  120.     jsr     _LVOWrite(a6)
  121.     move.l     tmpfile(pc),d1
  122.     jsr     _LVOClose(a6)
  123. tmperr    move.l     ioreq(pc),a1
  124.     move.w     #TR_ADDREQUEST,IO_COMMAND(a1)
  125.     move.l     delay(pc),a0
  126.     move.l     (a0),IOTV_TIME+TV_SECS(a1)
  127.     move.l     #0,IOTV_TIME+TV_MICRO(a1)
  128.     CALLEXEC SendIO
  129.     move.l     msgport(pc),a0
  130.     move.b     MP_SIGBIT(a0),d1
  131.     move.l     #SIGBREAKF_CTRL_C,d0
  132.     bset.l     d1,d0
  133.     move.b     signum(pc),d1
  134.     bset.l     d1,d0
  135.     jsr     _LVOWait(a6)
  136.     btst.l     #SIGBREAKB_CTRL_C,d0
  137.     bne     quit
  138.     move.b     signum(pc),d1
  139.     btst.l     d1,d0
  140.     bne     reboot
  141.     move.l     ioreq(pc),a1
  142.     jsr     _LVOWaitIO(a6)
  143.     beq     loop
  144. quit    move.l     a6,a1
  145.     move.w     #_LVOColdReboot,a0
  146.     move.l     oldcrb(pc),d0
  147.     jsr     _LVOSetFunction(a6)
  148.     move.l     ioreq(pc),a1
  149.     jsr     _LVOAbortIO(a6)
  150.     move.l     ioreq(pc),a1
  151.     jsr     _LVOWaitIO(a6)
  152.     move.l     #days,d1
  153.     move.l     dosbase(pc),a6
  154.     jsr     _LVODateStamp(a6)
  155.     move.l     logname(pc),d1
  156.     move.l     #MODE_READWRITE,d2
  157.     move.l     dosbase(pc),a6
  158.     jsr     _LVOOpen(a6)
  159.     move.l     d0,logfile
  160.     beq     logerr2
  161.     move.l     d0,d1
  162.     clr.l     d2
  163.     move.l     #OFFSET_END,d3
  164.     jsr     _LVOSeek(a6)
  165.     bsr     putdate
  166.     move.l     logfile(pc),d1
  167.     move.l     #quittxt,d2
  168.     jsr     _LVOFPuts(a6)
  169.     move.l     logfile(pc),d1
  170.     jsr     _LVOClose(a6)
  171. logerr2    move.l     tmpname(pc),d1
  172.     jsr     _LVODeleteFile(a6)
  173.     clr.l     d3
  174.     bra     logerr
  175. tmperr2    move.l     logfile(pc),d1
  176.     jsr     _LVOClose(a6)
  177. logerr    move.l     rdargs(pc),d1
  178.     jsr     _LVOFreeArgs(a6)
  179. argserr    move.l     ioreq(pc),a1
  180.     CALLEXEC CloseDevice
  181. deverr    move.l     ioreq(pc),a0
  182.     jsr     _LVODeleteIORequest(a6)
  183. reqerr    move.l     msgport(pc),a0
  184.     jsr     _LVODeleteMsgPort(a6)
  185. mperror    move.b     signum(pc),d0
  186.     jsr     _LVOFreeSignal(a6)
  187. sigerr    move.l     d3,d1
  188.     clr.l     d2
  189.     move.l     dosbase(pc),a6
  190.     jsr     _LVOPrintFault(a6)
  191.     move.l     dosbase(pc),a1
  192.     CALLEXEC CloseLibrary
  193. doserr    move.l     d3,d0
  194.     rts
  195. reboot    move.l     #days,d1
  196.     move.l     dosbase(pc),a6
  197.     jsr     _LVODateStamp(a6)
  198.     move.l     logname(pc),d1
  199.     move.l     #MODE_READWRITE,d2
  200.     move.l     dosbase(pc),a6
  201.     jsr     _LVOOpen(a6)
  202.     move.l     d0,logfile
  203.     beq     logerr3
  204.     move.l     d0,d1
  205.     clr.l     d2
  206.     move.l     #OFFSET_END,d3
  207.     jsr     _LVOSeek(a6)
  208.     bsr     putdate
  209.     move.l     logfile(pc),d1
  210.     move.l     #rebtxt,d2
  211.     jsr     _LVOFPuts(a6)
  212.     move.l     logfile(pc),d1
  213.     jsr     _LVOClose(a6)
  214. logerr3    move.l     tmpname(pc),d1
  215.     jsr     _LVODeleteFile(a6)
  216.     move.l     #volume1,d1
  217.     jsr     _LVOInhibit(a6)
  218.     lea     volume1(pc),a0
  219.     lea     volume2(pc),a1
  220. comp    move.b     (a0)+,d0
  221.     move.b     (a1)+,d1
  222.     cmp.b     d0,d1
  223.     bne     differ
  224.     tst.b     d0
  225.     bne     comp
  226.     bra     same
  227. differ    move.l     #volume2,d1
  228.     jsr     _LVOInhibit(a6)
  229. same    tst.l     fix39(pc)
  230.     beq     nofix39
  231.     lea     gfxname(pc),a1
  232.     clr.l     d0
  233.     CALLEXEC OpenLibrary
  234.     tst.l     d0
  235.     beq     nofix39
  236.     move.l     d0,a6
  237.     sub.l     a1,a1
  238.     jsr     _LVOLoadView(a6)
  239.     jsr     _LVOWaitTOF(a6)
  240.     jsr     _LVOWaitTOF(a6)
  241. nofix39    move.l     oldcrb(pc),a0
  242.     move.l     4.w,a6
  243.     jmp     (a0)
  244. putdate    move.l     #days,d1
  245.     jsr     _LVODateToStr(a6)
  246.     move.l     logfile(pc),d1
  247.     move.l     #strday,d2
  248.     jsr     _LVOFPuts(a6)
  249.     move.l     logfile(pc),d1
  250.     move.l     #strdate,d2
  251.     jsr     _LVOFPuts(a6)
  252.     move.l     logfile(pc),d1
  253.     move.l     #strtime,d2
  254.     jmp     _LVOFPuts(a6)
  255. finddn    move.b     (a0)+,d0
  256.     cmp.b     #':',d0
  257.     bne     finddn
  258.     clr.b     (a0)
  259.     rts
  260. newcrb    move.l     sigtask(pc),a1
  261.     clr.l     d0
  262.     move.b     signum(pc),d1
  263.     bset.l     d1,d0
  264.     CALLEXEC Signal
  265.     clr.l     d0
  266.     jmp     _LVOWait(a6)
  267.  
  268. dosbase    dc.l     0
  269. msgport    dc.l     0
  270. ioreq    dc.l     0
  271. rdargs    dc.l     0
  272. tmpname    dc.l     0
  273. logname    dc.l     0
  274. delay    dc.l     0
  275. fix39    dc.l     0
  276. days    dc.l     0
  277. minutes    dc.l     0
  278. ticks    dc.l     0
  279.     dc.b     FORMAT_DOS
  280.     dc.b     0
  281.     dc.l     strday
  282.     dc.l     strdat2
  283.     dc.l     strtim2
  284. logfile    dc.l     0
  285. tmpfile    dc.l     0
  286. oldcrb    dc.l     0
  287. sigtask    dc.l     0
  288. signum    dc.b     0
  289.  
  290.     dc.b     0,'$VER:PowerTools v1.4 (29.01.2002)'
  291.     dc.b     $0A,'by Pavel Fedin <sonic@sonic.misa.ac.ru>',0
  292. dosname    dc.b     'dos.library',0
  293. gfxname    dc.b     'graphics.library',0
  294. devname    dc.b     'timer.device',0
  295. argstr    dc.b     'TIMEFILE/A,LOGFILE/A,DELAY/N,FIX39/S',0
  296. starttx    dc.b     ' - system started.',$0A,0
  297. warntxt    dc.b     ' - system failure detected.',$0A,0
  298. quittxt    dc.b     ' - BREAK signal received, logger exited.',$0A,0
  299. rebtxt    dc.b     ' - system rebooting.',$0A,0
  300.  
  301. strday    dcb.b     LEN_DATSTRING
  302.     dc.b     0
  303. strdate    dc.b     ' '
  304. strdat2    dcb.b     LEN_DATSTRING
  305.     dc.b     0
  306. strtime    dc.b     ' '
  307. strtim2    dcb.b     LEN_DATSTRING
  308.     dc.b     0
  309. volume1    dcb.b     33
  310.     dc.b     0
  311. volume2    dcb.b     33
  312.     dc.b     0